package com.chl.legou.security.controller;

import com.chl.legou.core.controller.BaseController;
import com.chl.legou.security.config.TokenDecode;
import com.chl.legou.security.po.Address;
import com.chl.legou.security.service.IAddressService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.oauth2.provider.token.TokenStore;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.List;
import java.util.Map;

/**
 * @author chlong
 * @date 2022/2/26
 */
@RestController
@RequestMapping(value = "/address")
public class AddressController extends BaseController<IAddressService, Address> {

    @Autowired
    private TokenDecode tokenDecode;

    @Override
    @ApiOperation(value = "查询",notes = "根据实体条件查询")
    @RequestMapping(value = "/list",method = {RequestMethod.POST,RequestMethod.GET})
    public List<Address> list(Address entity){
        Map<String,String> user = null;
        try {
            user = tokenDecode.getUserInfo();
        } catch (IOException e) {
            e.printStackTrace();
        }
        String username = user.get("user_name");
        entity.setUsername(username);
        return service.list(entity);
    }
}
